<!-- 登录后状态显示 -->
<template>
  <div class="login-states" :class="insideClasses" v-if="isHide">
    <div class="login-status-main">
      <div class="login-status-list">
        <div class="login-status-item">
          <div class="login-status-icon" v-if="!userLoginStatus.content">
            <Icon type="ios-close-circle-outline" color="#f00" size="48" />
          </div>
          <h3>{{ userLoginStatus.title }}</h3>
          <p v-if="userLoginStatus.content">{{ userLoginStatus.content }}</p>
          <div class="login-status-btn" v-if="userLoginStatus">
            <div v-for="item in userLoginStatus.btnList" :key="item.id">
              <Button @click="openPage(item)" type="primary">{{
                item.name
              }}</Button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/javascript">
import { mapState, mapGetters } from "vuex";

import { GetLoginAfterStatus } from "@/api/account";

export default {
  name: "login-status",
  computed: {
    ...mapState("admin/layout", [
      "isFullscreen",
      "menuCollapse",
      "siderFix",
      "isMobile",
    ]),
    ...mapGetters("admin/menu", ["hideSider"]),
    insideClasses() {
      return {
        "i-layout-inside-fix-with-sider": this.siderFix,
        "i-layout-inside-fix-with-sider-collapse":
          this.siderFix && this.menuCollapse,
        "i-layout-inside-with-hide-sider": this.hideSider,
        "i-layout-inside-mobile": this.isMobile,
      };
    },
  },
  data() {
    return {
      loginStatusList: {

        newCompanyAuditing: {
          id: 1,
          title: "企业信息审核中",
          content: "企业信息审核中，一般审核需要5-7个工作日，请耐心等待",
          btnList: [
            {
              id: 1,
              name: "查看详情",
              url: "/myEnterprise",
            },
          ],
        },
        existsNewCompanyAuditNotPass: {
          id: 1,
          title: "企业信息审核未通过",
          content: "",
          btnList: [
            {
              id: 1,
              name: "查看详情",
              url: "/myEnterprise",
            },
            {
              id: 2,
              name: "加入现有企业",
              url: "/myEnterprise?isJoin=1",
            },
          ],
        },
        // 等待用户授权
        existsTodoDistributionRole: {
          id: 1,
          title: "用户信息等待授权",
          content: "企业信息审核中，一般审核需要5-7个工作日，请耐心等待",
          btnList: [
            {
              id: 1,
              name: "查看详情",
              url: "/setting/user",
            },
            {
              id: 2,
              name: "注册新企业",
              url: "/createEditCompany?isNew=1",
            },
            {
              id: 3,
              name: "加入现有企业",
              url: "/myEnterprise?isJoin=1",
            },
          ],
        },
        existsUnJoinCompany: {
          id: 1,
          title: "用户已被移除该公司",
          content: "企业信息审核中，一般审核需要5-7个工作日，请耐心等待",
          btnList: [
            {
              id: 1,
              name: "查看详情",
              url: "/setting/user",
            },
            {
              id: 2,
              name: "注册新企业",
              url: "/createEditCompany",
            },
            {
              id: 3,
              name: "加入现有企业",
              url: "/myEnterprise?isJoin=1",
            },
          ],
        },
        existsNewCompanyAuditPass: {
          id: 1,
          title: "企业信息审核已通过",
          content: "",
          btnList: [
            {
              id: 1,
              name: "开始使用",
              url: "/home",
            },
          ],
        },
        // 用户撤回提交企业信息审核
        existsNewCompanyCancelAudit:{
          id: 1,
          title: "提交信息已被撤回",
          content: "您的企业信息已被撤回，请从新提交或注册新的企业",
          btnList: [
            {
              id: 1,
              name: "查看详情",
              url: "/setting/user",
            },
            {
              id: 2,
              name: "编辑企业信息",
              url: "/createEditCompany?type=all",
            },
            {
              id: 3,
              name: "加入现有企业",
              url: "/myEnterprise?isJoin=1",
            },
          ],
        }
        // 用户等待授权
        // existsUnJoinCompany1: {
        //   id: 1,
        //   title: "用户等待授权",
        //   content: "用户信息审核中，一般审核需要5-7个工作日，请耐心等待",
        //   btnList: [
        //     {
        //       id: 1,
        //       name: "查看详情",
        //       url: "/setting/user",
        //     },
        //     {
        //       id: 2,
        //       name: "注册新企业",
        //       url: "/createEditCompany",
        //     },
        //     {
        //       id: 3,
        //       name: "加入现有企业",
        //       url: "/myEnterprise?isJoin=1",
        //     },
        //   ],
        // },
      },
      userLoginStatus: {
        title: "",
        btnList: [],
      },
      isHide: false,
      isLoading: false,
    };
  },
  watch: {
    $route(to, from) {
      let useStatus = localStorage.getItem("useStatus");
      console.log(to, useStatus, "this.getLoginAfterStatusData();");
      // 当前路由下不显示
      let routerList = [
        "/myEnterprise",
        "/setting/user",
        "/createEditCompany",
      ];

      if (!useStatus && !routerList.includes(to.path)) {
        this.getLoginAfterStatusData();
      }

      if (routerList.includes(to.path)) {
        this.isHide = false;
        this.$emit("update:isUpdateStatus", false);
      }
    },
  },
  methods: {
    async getLoginAfterStatusData() {
      this.$emit("update:isUpdateStatus", false);
      let data = await GetLoginAfterStatus({});
      // data = {
      //   existsNewCompanyAuditPass: true,
      // };
      for (let item in data) {
        if (data[item] && !data.existsNewCompanyAuditPass) {
          this.isHide = true;
          this.$emit("update:isUpdateStatus", true);
          this.userLoginStatus = this.loginStatusList[item];
        }
      }
    },
    openPage(item) {
      console.log(item, "a");
      if (item.name == "开始使用") {
        localStorage.setItem("useStatus", item.name);
        this.isHide = false;
        this.$emit("update:isUpdateStatus", false);
        return;
      }
      this.$router.push({
        path: item.url,
      });
    },
  },
  created() {
    let useStatus = localStorage.getItem("useStatus");
    let routerList = ["/myEnterprise", "/setting/user", "/createEditCompany"];
    let path = this.$route.path;
    if (!useStatus && !routerList.includes(path)) {
      this.getLoginAfterStatusData();
    }
  },
  mounted() {},
};
</script>

<style scoped lang="less">
.login-states {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: rgba(255, 255, 255, 0.9);
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-status-item {
    color: #fff;
    text-align: center;
    h3 {
      color: #333;
    }
    p {
      color: #999;
      margin: 10px 0;
    }
  }
}
.login-status-icon {
  margin-bottom: 20px;
}
.login-status-btn {
  display: flex;
  justify-content: center;
  .ivu-btn {
    margin: 20px 10px;
  }
}
</style>
